<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="kr.co.insoft.framework.config.Authorities" %>
<c:set var="CONTEXT">${pageContext.request.contextPath}</c:set>
<c:set var="cssUrl">${pageContext.request.contextPath}/resources/css</c:set>
<c:set var="jsUrl">${pageContext.request.contextPath}/resources/js</c:set>
<spring:message code="button.search.text" var="searchText"/>
<div class="col-sm-12 page-header custom-page-header">
	<h1><spring:message code="menu.template.script"/></h1>
	<small><spring:message code="menu.template.script.desc"/></small>
</div>
<form:form modelAttribute="pagingModel" role="form" cssClass="col-sm-12">
	<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
	<input id="currentPage" name="currentPage" type="hidden" value="${pagingModel.currentPage}" />
	<!-- 검색 -->
	<div class="col-sm-12 form-group">
		<div class="col-sm-12 text-right">
			<div class="col-sm-offset-7 col-sm-3">
				<div class="input-group">
					<input type="text" placeholder="${searchText }" name="searchAndCondition['scriptName']" class="form-control" value="${pagingModel.searchAndCondition['scriptName']}" />
					<span class="input-group-btn">
						<button class="btn btn-primary"><spring:message code="button.search"/></button>
					</span>
				</div>
			</div>
			<div class="col-sm-2">
			<form:select path="viewRow" cssClass="form-control">
				<form:option value="10">10 개</form:option>
				<form:option value="25">25 개</form:option>
				<form:option value="50">50 개</form:option>
				<form:option value="100">100 개</form:option>
			</form:select>
			</div>
		</div>
	</div>
	<!-- 스크립트 리스트 -->
	<div class="form-group">
		<table class="table table-hover">
			<thead>
				<tr>
					<th><spring:message code="template.script.name"/></th>
					<th><spring:message code="common.writer"/></th>
					<th><spring:message code="common.updatedDate"/></th>
				</tr>
			</thead>
			<tbody>
				<c:choose>
					<c:when test="${empty pagingModel.lists }">
						<tr class="warning  text-center">
							<td colspan="3"><spring:message code="list.no.result"/></td>
						</tr>
					</c:when>
					<c:otherwise>
						<c:forEach items="${pagingModel.lists }" var="item">
						<tr>
							<td><a href="#" class="btn_link"  data-link="./view?scriptid=${item.scriptid }">${item.scriptName }</a></td>
							<td>${item.writer }</td>
							<td>${item.updatedDate }</td>
						</tr>
						</c:forEach>
					</c:otherwise>
				</c:choose>
			</tbody>
		</table>
	</div>
	<!-- 페이징 -->
	<div class="form-group text-center">
		<c:if test="${not empty pagingModel.lists }">
		<ul class="pagination">
			<li><a href="#" class="pages" data-page="${pagingModel.paging.previousBlock }">&laquo;</a></li>
			<c:forEach items="${pagingModel.paging.pages }" var="pages">
			<c:choose>
				<c:when test="${pages eq pagingModel.paging.currentPageNum }">
					<li class="active"><a href="#" class="pages" data-page="${pages }">${pages }</a></li>
				</c:when>
				<c:otherwise>
					<li><a href="#" class="pages" data-page="${pages }">${pages }</a></li>
				</c:otherwise>
			</c:choose>
			</c:forEach>
			<li><a href="#" class="pages" data-page="${pagingModel.paging.nextBlock}">&raquo;</a></li>
		</ul>
		</c:if>
	</div>
	<!-- 하단 버튼 -->
	<div class="form-group text-right">
		<c:if test="${not empty pagingModel.searchAndCondition['scriptName']}">
		<button type="button" class="btn btn-default btn_link" data-link="./lists"><spring:message code="button.list"/></button>
		</c:if>
		<c:if test="${fn:contains(buttons , Authorities.CREATE)}">
		<button type="button" class="btn btn-primary btn_link" data-link="./createForm"><spring:message code="button.create"/></button>
		</c:if>
	</div>
</form:form>
